package comparisons

import (
	"HandWritingJVM/instructions/base"
	"HandWritingJVM/rtda"
)

type IFEQ struct {
	base.BranchInstruction
}

func (self *IFEQ) Execute(frame *rtda.Frame) {
	v := frame.OperandStack().PopInt()
	if v == 0 {
		base.Branch(frame, self.Offset)
	}

}

type IFNE struct {
	base.BranchInstruction
}

func (self *IFNE) Execute(frame *rtda.Frame) {
	v := frame.OperandStack().PopInt()
	if v != 0 {
		base.Branch(frame, self.Offset)
	}
}

type IFLT struct {
	base.BranchInstruction
}

func (self *IFLT) Execute(frame *rtda.Frame) {
	v := frame.OperandStack().PopInt()
	if v < 0 {
		base.Branch(frame, self.Offset)
	}
}

type IFLE struct {
	base.BranchInstruction
}

func (self *IFLE) Execute(frame *rtda.Frame) {
	v := frame.OperandStack().PopInt()
	if v <= 0 {
		base.Branch(frame, self.Offset)
	}
}

type IFGT struct {
	base.BranchInstruction
}

func (self *IFGT) Execute(frame *rtda.Frame) {
	v := frame.OperandStack().PopInt()
	if v > 0 {
		base.Branch(frame, self.Offset)
	}
}

type IFGE struct {
	base.BranchInstruction
}

func (self *IFGE) Execute(frame *rtda.Frame) {
	v := frame.OperandStack().PopInt()
	if v >= 0 {
		base.Branch(frame, self.Offset)
	}
}
